package com.we.wecc.aw.api.controller;

import com.we.wecc.aw.db.model.AwardWin;
import com.we.wecc.aw.mid.model.in.AwardWinIn;
import com.we.wecc.aw.mid.model.out.AwardWinOut;
import com.we.wecc.aw.mid.service.AwardWinService;
import com.we.wecc.bg.api.controller.BackController;
import com.x.share.db.model.Pagination;
import com.x.share.mid.exception.HelperException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@Api(value = "获奖人信息接口")
@RestController
@RequestMapping("/wecc/aww")
public class AwardWinController extends BackController{
    @Resource
    AwardWinService awardWinService;

    @ApiOperation(value = "获取获奖人信息列表", notes= "获取获奖人信息列表", response = AwardWinOut.class)
    @RequestMapping(value = "/getAwardWinList", method = { RequestMethod.GET})
    public @ResponseBody
    Map<String, Object> getAwardWinList(
            @ApiParam(value = "当前页,默认第1页", defaultValue = "1") @RequestParam("pn") Integer pageNo,
            @ApiParam(value = "每页记录数", defaultValue = "10") @RequestParam("ps") Integer pageSize,
            @ApiParam(value = "应用id") @RequestHeader("appId") String appId,
            @ApiParam(value = "应用accessToken") @RequestHeader("atk") String atk
    )throws HelperException {
        Pagination<AwardWinOut> page = awardWinService.getAwardWinList(pageNo,pageSize);
        return success(page);
    }

    @ApiOperation(value = "根据活动获取获奖人信息列表", notes= "根据活动获取获奖人信息列表", response = AwardWinOut.class)
    @RequestMapping(value = "/getAwardWinByAwardId", method = { RequestMethod.GET})
    public @ResponseBody Map<String, Object> getAwardWinListByAwardId(
            @ApiParam(value = "云购期数id") @RequestParam("awardId") Integer awardId,
            @ApiParam(value = "应用id") @RequestHeader("appId") String appId,
            @ApiParam(value = "应用accessToken") @RequestHeader("atk") String atk
    )throws HelperException {
        AwardWinOut page = awardWinService.getAwardWinByAwardId(awardId);
        return success(page);
    }

    @ApiOperation(value = "添加或修改获奖人信息", notes= "添加或修改获奖人信息", response = AwardWin.class)
    @RequestMapping(value = "/saveAwardWin", method = { RequestMethod.POST})
    public @ResponseBody Map<String, Object> saveAwardWin(
            @RequestBody AwardWinIn in,
            @ApiParam(value = "应用id") @RequestHeader("appId") String appId,
            @ApiParam(value = "应用accessToken") @RequestHeader("atk") String atk
    ) throws HelperException {
        AwardWin awardWin = awardWinService.saveAwardWin(in);
        return success(awardWin);
    }
}
